package com.example.prom.qianduoduo.y2023.excel;

import com.example.prom.listener.ExcelListener;
import com.example.prom.ok.y2023.work.maxmind.MaxMindIpReaderVO;
import com.example.prom.qianduoduo.y2023.model.MedicineModel;
import com.example.prom.strategy.excel.CustomCellStyleStrategy;
import com.example.prom.strategy.excel.CustomColumnWidthStrategy;
import lombok.extern.slf4j.Slf4j;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.alibaba.excel.EasyExcelFactory.read;
import static com.alibaba.excel.EasyExcelFactory.write;

@Slf4j
public class MaxMindHandler {

    public static void main(String[] args) throws Exception{
        List<MedicineModel> medicineModels = readExcel();
//        List<MedicineModel> collect = medicineModels.stream().sorted(Comparator.comparing(MedicineModel::getNumber)).collect(Collectors.toList());
//        List<MedicineModel> medicineModels2 = readExcel2();
//        Map<Integer, MedicineModel> medicineModels2Map = medicineModels2.stream().collect(Collectors.toMap(MedicineModel::getNumber, x -> x, (k1, k2) -> k1));
//        for (MedicineModel medicineModel : collect) {
//            int number = medicineModel.getNumber();
//            if (medicineModels2Map.containsKey(number)){
//                MedicineModel medicineModel1 = medicineModels2Map.get(number);
//                medicineModel.setGroup(medicineModel1.getGroup());
//            } else {
//                medicineModel.setGroup("A");
//            }
//        }
//
//        writeExcel(medicineModels);
    }


    public static List<MedicineModel> readExcel() {
        String fileName = "C:\\Users\\hp\\Desktop\\1.xlsx";
        ExcelListener<MedicineModel> excelListener = new ExcelListener<>();
        read(fileName, MedicineModel.class, excelListener).sheet().doRead();
        List<MedicineModel> dataList = excelListener.getDataList();
        Map<Integer, String> headMap = excelListener.getHeadMap();
        for (Integer integer : headMap.keySet()) {
            System.out.println(headMap.get(integer));
        }
        return dataList;
    }

    public static List<MedicineModel> readExcel2() {
        String fileName = "C:\\Users\\hp\\Desktop\\2.xls";
        ExcelListener<MedicineModel> excelListener = new ExcelListener<>();
        read(fileName, MedicineModel.class, excelListener).sheet().doRead();
        List<MedicineModel> dataList = excelListener.getDataList();
        return dataList;
    }

    public static void writeExcel(List<MedicineModel> writerList){
        String writeFileName = "C:\\Users\\hp\\Desktop\\3.xls";
        write(writeFileName, MedicineModel.class).sheet().doWrite(writerList);
    }

}
